#ifndef UTILITIES_H
#define UTILITIES_H

#include <QObject>
#include <QUrl>
#include <QSettings>

class Utilities : public QObject
{
    Q_OBJECT
public:
	explicit Utilities(QObject *parent = 0){settings = new QSettings("qtweather", "qtweather", this);}

	/**
	  Decode a url encoded string
	  @param string the url to decode
	  @return The decoded url from string
	  */
	Q_INVOKABLE QString decode(QByteArray string){
		return QUrl::fromPercentEncoding(string);
	}

	/**
	Get the zipcode of a corresponding home
	@param homeNum home identifier (ie "home1")
	@return The zipcode of homeNum, else "" if none exists
	*/
	Q_INVOKABLE QVariant home(QString homeNum){
		return settings->value(homeNum, "null").toString();
	}

	/**
	  Set the zipcode of a home
	  @param homeNum home identifier (ie "home1")
	  @param zipcode The zipcode to be set
	  */
	Q_INVOKABLE void setHome(QString homeNum, QString zipcode){
		settings->setValue(homeNum, zipcode);
	}

	/**
	  Get the number of the default home
	  @return an int representing the home zipcode
	  to load on startup
	  */
	Q_INVOKABLE int defaultHome(){
		return settings->value("default").toInt();
	}

	/**
	  Set the number of the home to load on startup
	  @param homeNum the number of the new default home
	  */
	Q_INVOKABLE void setDefaultHome(int homeNum){
		settings->setValue("default", homeNum);
	}


private:
	QSettings* settings;

};

#endif
